<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <link rel="stylesheet" href="/static/style.css">
</head>
<body>
    <div class="wrapper">
        <div class="panel layui-panel">
            <div class="layui-tab layui-tab-brief" lay-filter="tab">
                <ul class="layui-tab-title">
                    <li class="layui-this" lay-id="tabList">登录日志</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <table class="layui-hide" id="table" lay-filter="table"></table>

                        <script type="text/html" id="TB">
                            <a class="layui-btn layui-bg-red layui-btn-sm" lay-event="clear"><i class="layui-icon layui-icon-clear"></i> 清空</a>
                        </script> 
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<script src="/static/layui/layui.js"></script>
<script>
layui.use(function() {
    var $ = layui.jquery,
        table = layui.table;

    table.render({
        id: 'table',
        elem: '#table',
        url: "{:url('admin/log/log')}",
        method: 'post',
        toolbar: '#TB',
        defaultToolbar: ['filter', 'exports', 'print'],
        page: true,
        cols: [[
            {field: 'name', title: '用户名称'},
            {field: 'login_time', title: '登录时间'},
            {field: 'login_ip', title: '登录IP'},
        ]],
        height: 'full-141',
        skin: 'line',
        // done: function (res, curr, count, origin) {
        //     table.resize('table');
        // }
    });

    table.on('toolbar(table)', function(obj) {
        if (obj.event === 'clear') {
            layer.confirm('确定要清空所有日志吗？', {icon: 3}, function (index) {
                var loadIndex = layer.load();
                $.post("{:url('admin/log/logclear')}", function(res) {
                    layer.close(loadIndex);
                    if (res.code > 0) {
                        layer.alert(res.msg, {icon: 2});
                    } else {
                        layer.msg(res.msg, {time: 500});
                        table.reloadData('table');
                    }
                });
                layer.close(index);
            });
        }
    });    
});
</script>